package org.aphelie.chronicle.ui.forms;

import org.aphelie.chronicle.ArcScore;
import org.aphelie.chronicle.ArcTopic;
import org.aphelie.chronicle.ui.layout.ArcFormLayoutFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;

public class ArcScoresSection extends ArcTopicSection {

	public ArcScoresSection(ArcTopicPage page, Composite parent, ArcTopic topic) {
		super(page, parent, topic, Section.DESCRIPTION);
	}
	
	@Override
	protected void createClient(Section section) {
		section.setText(topic.getLabel());
		section.setLayout(ArcFormLayoutFactory.createClearTableWrapLayout(true, 4));
		TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
		section.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
		section.setLayoutData(data);
		section.setDescription(topic.getLabel());
		fillScores(section);
	}
	
	protected void fillScores(Section section) {
		Composite client = getToolkit().createComposite(section);
		client.setLayout(ArcFormLayoutFactory.createSectionClientGridLayout(false, 2));
		client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		client.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
		section.setClient(client);
		
		for(EObject content : topic.eContents()) {
			if (content instanceof ArcScore) {
				@SuppressWarnings("unused")
				ScoreEntry entry = new ScoreEntry(client, getToolkit(), this, (ArcScore) content);
			}
		}
	}
	
	

}
